// store/index.js
import { createStore } from 'vuex'

export default createStore({
  state: {
    currentUser: { username: localStorage.getItem('username') || '游客', userType: localStorage.getItem('userType') || 'user' },
    isBookRecommendationVisible: false
  },
  mutations: {
    updateUser(state, user) {
      state.currentUser = user
    },
    toggleBookRecommendation(state) {
      state.isBookRecommendationVisible = !state.isBookRecommendationVisible
    }
  },
  actions: {
    updateUser({ commit }, user) {
      commit('updateUser', user)
    },
    toggleBookRecommendation({ commit }) {
      commit('toggleBookRecommendation')
    }
  }
})
